let http = require('http')
let path = require('path')
let fs = require('fs')

let server = http.createServer()

server.on('request',(req,res)=>{
    let url = req.url
    let fullpath = path.join(__dirname, 'static', url)
    if(url ==='/'){
        fullpath = path.join(__dirname, 'static', 'index.html')
    }
    fs.readFile(fullpath, (err,data)=>{
        if(err){
            return res.end(err.message)
        }
        return res.end(data)
    })
})

server.listen(3002,()=>{
    console.log('ok')
})


